package com.github.chain.admin.server.controller;

import com.github.chain.admin.common.domain.Menu;
import com.github.chain.admin.common.domain.Role;
import com.github.chain.admin.common.domain.RoleMenu;
import com.github.chain.admin.common.domain.User;
import com.github.framework.core.page.DataPage;
import com.github.chain.admin.common.request.RoleRequest;
import com.github.chain.admin.server.service.RoleService;
import com.github.framework.core.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@RestController
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/findRoleByUserId/{userId}")
    Result<Boolean> findRoleByUserId(@PathVariable("userId") Long userId){
        return roleService.findRoleByUserId(userId);
    }

    @GetMapping("/findRolePermissionsByUserId/{userId}")
    Result<Set<Role>> findRolePermissionsByUserId(@PathVariable("userId") Long userId){
        return roleService.findRolePermissionsByUserId(userId);
    }

    @PostMapping("/findRoleByPage")
    Result<DataPage<Role>> findRoleByPage(@RequestBody RoleRequest request){
        return roleService.findRoleByPage(request);
    }

    @GetMapping("/findRoleById/{id}")
    Result<Role> findRoleById(@PathVariable("id") Long id){
        return roleService.findRoleById(id);
    }

    @PostMapping("/updateRole")
    Result<Integer> updateRole(@RequestBody RoleRequest roleRequest){
        return roleService.updateRole(roleRequest);
    }

    @GetMapping("/deleteRoleById/{id}")
    Result<Integer> deleteRoleById(@PathVariable("id") Long id){
        return roleService.deleteRoleById(id);
    }

    @PostMapping("/deleteRoleListById")
    Result<Integer> deleteRoleListById(@RequestBody List<Long> list){
        return roleService.deleteRoleListById(list);
    }

    @PostMapping("/saveRole")
    Result saveRole(@RequestBody RoleRequest roleRequest){
        return roleService.saveRole(roleRequest);
    }

    @PostMapping("/authPermissions")
    Result authPermissions(@RequestBody RoleMenu roleMenu){
        return roleService.authPermissions(roleMenu);
    }

    @GetMapping("/findUserByRoleId/{id}")
    Result<List<User>> findUserByRoleId(@PathVariable("id") Long id){
        return roleService.findUserByRoleId(id);
    }

    @PostMapping("/enableRoleStatus")
    Result enableRoleStatus(@RequestBody List<Long> ids){
        return roleService.enableRoleStatus(ids);
    }

    @PostMapping("/disableRoleStatus")
    Result disableRoleStatus(@RequestBody List<Long> ids){
        return roleService.disableRoleStatus(ids);
    }

}
